﻿using MapleLeaf.IdentityServer.Models;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace MapleLeaf.IdentityServer.Controllers {

    public class BaseController : ControllerBase {

        #region 返回值处理
        /// <summary>
        /// 返回成功数据
        /// </summary>
        /// <param name="data">数据</param>
        /// <returns></returns>
        protected virtual IActionResult Success(object data) {
            return Ok(new ResultModel { code = StatusCodes.Status200OK, message = "响应成功", result = data });
        }
        /// <summary>
        /// 返回成功数据
        /// </summary>
        /// <param name="info">信息</param>
        /// <returns></returns>
        protected virtual IActionResult Success(string info) {
            return Ok(new ResultModel { code = StatusCodes.Status200OK, message = info });
        }
        /// <summary>
        /// 返回成功数据
        /// </summary>
        /// <param name="info">信息</param>
        /// <param name="data">数据</param>
        /// <returns></returns>
        protected virtual IActionResult Success(string info, object data) {
            return Ok(new ResultModel { code = StatusCodes.Status200OK, message = info, result = data });
        }
        /// <summary>
        /// 返回失败的数据
        /// </summary>
        /// <param name="error">错误信息</param>
        /// <returns></returns>
        protected virtual IActionResult Fail(string error) {
            return Ok(new ResultModel { code = StatusCodes.Status500InternalServerError, message = error });
        }
        #endregion


    }
}
